<?
ob_start();
include("common/header.html");
include("common/left.html");
$out_html=ob_get_contents();
ob_end_clean();

include("common/page.php");
//$_a->authVerify();

$dtypeT=array(0=>"购买产品",1=>"撤改订单",3=>"账户资金变化",4=>"供应商授信余额",5=>"利润",6=>"提现冻结",7=>"电子凭证费",8=>"短信息费",9=>"银行交易手续费",10=>"凭证费",11=>"供应商信用额度变化 ",12=>"取消提现");
$ptypeT=array(-1=>"支付宝",0=>"账号资金",1=>"支付宝",2=>"供应商可用资金",3=>"供应授信额度设置");
$r=array();
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:10;
$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$offset=($currentPage-1)*$pageSize;
if(isset($_REQUEST['act']) && $_REQUEST['act']=="Export")
{
	$offset=0;$pageSize=999999999;
	// $offset=0;$pageSize=9;
}


$where1="where 1=1";
$where1.=" and dmoney>0 ";
$dname=$_REQUEST['dname'];
if($dname&&is_numeric($dname)&&strlen($dname)==6){
    $str="select id from pft_member where account='$dname'";
    $GLOBALS['le']->query($str);
    while($row=$GLOBALS['le']->fetch_assoc()){
        $ids[]=$row['id'];
    }
    if(count($ids)!=0){
		$ids=implode(",",$ids);
		$where1.=" and fid in ($ids)";
	}else{
		$where1.=" and 1<>1";
	}
}elseif($dname=mysql_real_escape_string(trim($_REQUEST['dname']))){
	$ids=array();
	$str="select id from pft_member where dname like '%".$dname."%'";
	$GLOBALS['le']->query($str);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$ids[]=$row['id'];
	}
	if(count($ids)!=0){
		$ids=implode(",",$ids);
		$where1.=" and fid in ($ids)";
	}else{
		$where1.=" and 1<>1";
		$where2.=" and 1<>1";
	}
}
$day=date("Y-m-d");
if($beginDate=mysql_real_escape_string($_REQUEST['beginDate'])){
	$where1.=" and rectime>='$beginDate 00:00:00'";
}
if($endDate=mysql_real_escape_string($_REQUEST['endDate'])){
	$where1.=" and rectime<='$endDate 23:59:59'";
}
$where1.=" and dtype=3 and ptype=0";
$dnames=array();
$str="select id,dname,account from pft_member";
$GLOBALS['le']->query($str);
$dn=array();
while($row=$GLOBALS['le']->fetch_assoc()){
    $dn[$row['id'].'_'.$row['account']]=$row['dname'];
	$dnames[$row['id']]=$row['dname'];
}
//将商户的account，id，dname存入ainfo数组
$ainfo=$t=array();
foreach($dn as $key=>$d){
    $k=explode('_',$key);
    $t['id']=$k[0];
    $t['dname']=$d;
    $t['account']=$k[1];
    $ainfo[]=$t;
    unset($t);
}

$str="select id,fid,dmoney,lmoney,aid,rectime,dtype,opid,ptype,'' as ali_account from pft_member_journal $where1 order by rectime desc,id desc limit $offset,$pageSize";

// $str="(select id,fid,dmoney,lmoney,aid,orderid,daction,rectime,dtype,ptype,'' as ali_account from pft_member_journal $where1) UNION (select id,fid,money,'','',orderid,0,rectime,-1,-1,ali_account from pft_member_alipay  $where2) order by rectime desc,orderid desc limit $offset,$pageSize";
$GLOBALS['le']->query($str);
while($row=$GLOBALS['le']->fetch_assoc()){
	$r[]=$row;
}
foreach($r as $k=>$v){
    $sl="select dname from pft_member where id=".$v['opid'];
    $GLOBALS['le']->query($sl);
    $GLOBALS['le']->fetch_assoc();
    $r[$k]['operator']=$GLOBALS['le']->f('dname');
}
if($_REQUEST['cs']){
    echo $str;print_r($r);exit;
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=="Export"){

	$filename=date('YmdHis').'线下充值交易记录';
	$Ecel[0]['member']='充值商户';
	$Ecel[0]['rectime']='交易时间';
	$Ecel[0]['dmoney']='充值金额';
	$Ecel[0]['lmoney']='账户余额';
	$Ecel[0]['operator']='操作员';
	$i=1;
	foreach($r as $lid=>$row){
		//print_r($row);
		$n++;
        foreach($ainfo as $dinfo){
            if($dinfo['id']==$row['fid']){
                $Ecel[$n]['member']=$dinfo['dname'];
            }
        }
		$Ecel[$n]['rectime']=$row['rectime'];
		$Ecel[$n]['dmoney']=$row['dmoney']/100;
		$Ecel[$n]['lmoney']=$row['lmoney']/100;
		$Ecel[$n]['operator']=$row['operator'];
	}
	$xs = new SimpleExcel('UTF-8', true,'offorderList');
    $xs->addArray($Ecel);
    $xs->generateXML($filename);
	exit;
}
$str="select count(*) as total from pft_member_journal $where1";
$GLOBALS['le']->query($str);
$GLOBALS['le']->fetch_assoc();
$count=$GLOBALS['le']->f("total");
        
// $count=$count1+$count2;
// var_dump($count);
$currentPage=$_REQUEST['currentPage']?abs($_REQUEST['currentPage']):1;
$pageSize=$_REQUEST['pageSize']?abs($_REQUEST['pageSize']):10;
$offset=($currentPage-1)*$pageSize;
echo $out_html;
include("tpl/offRechaTrecord.tpl");
include("common/footer.html");
?>